﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RMSoftware.Models;
//using BusinessObjects;
using Entities;

namespace RMSoftware.Controllers
{
    public class PersonController : Controller
    {
        [HttpGet]
        public ActionResult ViewList()
        {
            DataManager dm = new DataManager();

            ViewData.Model = dm.Persons;

            //ViewData.Model = (new Person()).Retrieve();

            return View();
        }

        [HttpGet]
        public ActionResult ViewDetailsByUsername(string username)
        {
            return RedirectToAction("ViewDetails", "Person", new { personId = (new DataManager()).GetPersonIdByUsername(username) });
        }

        [HttpGet]
        public ActionResult ViewDetails(Guid personId)
        {
            DataManager dm = new DataManager();

            Person person = dm.GetPerson(personId);

            ViewBag.PersonName = String.Format("{0} {1}", person.FirstName, person.LastName);
            ViewBag.PersonMeasures = dm.GetPersonMeasures(personId);

            return View(person);
        }

        [HttpPost]
        public ActionResult Create(Person obj)
        {
            obj.PersonId = Guid.NewGuid();
            (new DataManager()).AddPerson(obj);
            return RedirectToAction("ViewList");
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Delete(Guid id)
        {
            (new DataManager()).DeletePerson(id);

            return RedirectToAction("ViewList");
        }
    }
}
